from db_handler import MysqlHander
from my_http import MyHttp
import urllib.request
from bs4 import BeautifulSoup
import glob
import jieba
import re
import threading
import hashlib
import time
from selenium import webdriver
import json
import os

'''
郑州交易所合约数据
'''

#chromedriver = "D:\\chromedriver.exe"
#os.environ["webdriver.chrome.driver"] = chromedriver
#driver = webdriver.Chrome(executable_path="D:\\chromedriver.exe")
#driver = webdriver.Chrome(chromedriver)
file = open('shidagudong.txt', 'w', encoding = 'utf-8')


class ZhengjiaosuoHeyue:
    def __init__(self):
        self.db = MysqlHander("config.ini")
        
    def insert_data(self, date, title, type_id, url, site, status):
        sql = "insert into macro_data_temp (Fdate, Ftype, Ftitle, Furl, Fsite, Fstatus, Fcreate_time, Fmodify_time) values "
        sql += "('" + date + "'," + str(type_id) + ",'" + title + "','" + url + "','" + site + "'," + str(status) + ", now(), now());"
        
        print(sql)
        try:
            #pass
            self.db.execute_not_safe(sql)
        except Exception as e:
            print(str(e))
            pass

    
    def heyue(self):

        http_data = MyHttp.bs4_utf8_data("http://app.czce.com.cn/cms/pub/search/searchjyyl.jsp")
        print(http_data)
        '''
        driver.get("http://app.czce.com.cn/cms/pub/search/searchjyyl.jsp")
        print(driver.page_source)
        tbody = driver.find_element_by_id("monthTr")
        tds = tbody.find_element_by_tag_name("td")
        print(tds)
        '''
    
    def get_data(self):
        self.heyue()


if __name__ == '__main__':
    d = ZhengjiaosuoHeyue()
    d.get_data()
